package com.cw.jeeyt.service.converter.api;

import java.util.ArrayList;
import java.util.List;

import com.google.common.collect.Iterators;
import com.google.common.collect.Lists;
import com.cw.jeeyt.service.bo.api.ApiDataEntryBo;
import com.cw.jeeyt.dao.model.api.ApiDataEntryDo;
import com.cw.lang.common.utils.CollectionUtil;

/**
 * 接口字段信息转换类
 *
 * @author chenw
 * @date 2019-03-10 13:05:36
 */
public class ApiDataEntryConverter {

    /**
     * do转bo
     *
     * @param model
     * @return
     */
    public static ApiDataEntryBo do2Bo(ApiDataEntryDo model) {
        if (model == null) {
            return null;
        }
        ApiDataEntryBo bo = new ApiDataEntryBo();
        bo.setId(model.getId());
        bo.setColumnCode(model.getColumnCode());
        bo.setColumnName(model.getColumnName());
        bo.setColumnLength(model.getColumnLength());
        bo.setColumnType(model.getColumnType());
        // bo.setEnumCode(model.getEnumCode());
        // bo.setPojoCode(model.getPojoCode());
        bo.setColumnSqlCode(model.getColumnSqlCode());
        bo.setColumnSqlType(model.getColumnSqlType());
        bo.setColumnComment(model.getColumnComment());
        bo.setCreateBy(model.getCreateBy());
        bo.setCreateDate(model.getCreateDate());
        bo.setUpdateBy(model.getUpdateBy());
        bo.setUpdateDate(model.getUpdateDate());
        return bo;
    }

    /**
     * bo转do
     *
     * @param bo
     * @return
     */
    public static ApiDataEntryDo bo2Do(ApiDataEntryBo bo) {
        if (bo == null) {
            return null;
        }
        ApiDataEntryDo model = new ApiDataEntryDo();
        model.setId(bo.getId());
        model.setColumnCode(bo.getColumnCode());
        model.setColumnName(bo.getColumnName());
        model.setColumnLength(bo.getColumnLength());
        model.setColumnType(bo.getColumnType());
        // model.setEnumCode(bo.getEnumCode());
        // model.setPojoCode(bo.getPojoCode());
        model.setColumnSqlCode(bo.getColumnSqlCode());
        model.setColumnSqlType(bo.getColumnSqlType());
        model.setColumnComment(bo.getColumnComment());
        model.setCreateBy(bo.getCreateBy());
        model.setCreateDate(bo.getCreateDate());
        model.setUpdateBy(bo.getUpdateBy());
        model.setUpdateDate(bo.getUpdateDate());
        return model;
    }

    /**
     * doList转boList
     *
     * @param doList
     * @return
     */
    public static List<ApiDataEntryBo> doList2BoList(List<ApiDataEntryDo> doList) {
        if (CollectionUtil.isEmpty(doList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(doList.iterator(), ApiDataEntryConverter::do2Bo));
    }

    /**
     * boList转doList
     *
     * @param boList
     * @return
     */
    public static List<ApiDataEntryDo> boList2DoList(List<ApiDataEntryBo> boList) {
        if (CollectionUtil.isEmpty(boList)) {
            return new ArrayList<>();
        }
        return Lists.newArrayList(Iterators.transform(boList.iterator(), ApiDataEntryConverter::bo2Do));
    }
}